package com.lagou.test;

import com.lagou.dao.EmployeesDao;
import com.lagou.domain.Employees;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.logging.SimpleFormatter;

public class MybatisTest2 {

    @Test
    public void testEmployees() throws IOException {
        //加载核心配置文件
        InputStream resourceAsStream = Resources.getResourceAsStream("SqlMapConfig.xml");
        //获得SqlSessionFactory工厂对象
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(resourceAsStream);
        //获得SqlSession会话对象
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //获得mapper代理对象
        EmployeesDao mapper = sqlSession.getMapper(EmployeesDao.class);

        //测试查询所有的员工信息
        List<Employees> allEmployees = mapper.findAllEmployees();
        for(Employees employees:allEmployees){
            System.out.println(employees);
        }
//        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
//        Date date = new Date();
//        String time = sdf.format(date);
//        Employees employees = new Employees();
//        employees.setEmp_name("Blank");
//        employees.setJob_name("客户经理");
//        employees.setJoin_date(new Date());
//        employees.setTelephone("13333444445");
//        employees.setEmp_id(4);
//        employees.setDepart_id(2);
////        //执行
////        Employees employeesById = mapper.findEmployeesById(4);
////
////        System.out.println(employeesById);
//
//        mapper.newEmployee(employees);
//
//        sqlSession.commit();
//
//        sqlSession.close();
    }

}
